#include "dtt_qwidget.h"

//static QGLFormat glFormat()
//{
//    QGLFormat format;
//    format.setVersion(4, 0);
//    format.setProfile(QGLFormat::CoreProfile); // Requires >=Qt-4.8.0
//    format.setSampleBuffers(false);
//    return format;
//}

DttQWidget::DttQWidget( QWidget* parent)
    : QGLWidget(parent)
{
}

DttQWidget::~DttQWidget()
{
}

void DttQWidget::initializeGL()
{
    if (GLEW_OK != glewInit())
    {
        throw std::exception("GLEW initialization failed.");
    }
 
    GpuInfo::printGpuInfo();
    int i = -1;
    std::string errcode;
    // make sure no gl error before entering subroutine
    do 
    {
        i++;
        errcode = GpuInfo::getError();
    } while ((i < 8) && ("GL_NO_ERROR" != errcode));
   
    _dttScene.init();
}

void DttQWidget::resizeGL( int w, int h )
{
    _dttScene.onSizeChanged(w, h);
}

void DttQWidget::paintGL()
{
    _dttScene.onRender();
}

void DttQWidget::rotate( int x/*, float y, float z */)
{
    _dttScene.rotate(float(x)/10.0f/*, y, z*/);
    updateGL();
}
